package com.bilibili.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bilibili.entity.Category;
import com.bilibili.entity.CommonResult;
import com.bilibili.service.CategoryService;
import com.bilibili.service.impl.CategoryServiceImpl;

@SuppressWarnings("serial")//抑制serialVersionUID字段警告
@WebServlet("/queryAllCategory")
public class QueryAllCategoryServlet extends HttpServlet{
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("application/json; charset=utf-8");
		CategoryService cs = new CategoryServiceImpl();
		List<Category> c = cs.selectAllCategory();
		CommonResult cr = new CommonResult();
		if(c != null) {
			cr.setCode(200);
			cr.setData(c);
			response.getWriter().write(cr.toJSONString());
		}else {
			cr.setCode(409);
			response.getWriter().write(cr.toJSONString());
		}
	}
}
